package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.dto.NursingPlanPageParamDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Slf4j
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
public class NursingPlanController extends BaseController {

    @Autowired
    private NursingPlanService nursingPlanService;

    //分页条件查询
    @GetMapping("/search")
    @ApiOperation(value = "条件分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> getByPage(NursingPlanPageParamDto nursingPlanPageParamDto) {
        log.info("分页条件查询：{}", nursingPlanPageParamDto);
        PageResponse<NursingPlanVo> result = nursingPlanService.getPage(nursingPlanPageParamDto);
        return success(result);
    }

    //查询所有计划
    @GetMapping
    @ApiOperation(value = "查询所有计划")
    public ResponseResult<List<NursingPlanVo>> getAll() {
        log.info("查询所有计划：");
        List<NursingPlanVo> result = nursingPlanService.getAllPlan();
        return success(result);
    }

    //新增计划
    @PostMapping
    @ApiOperation(value = "新增计划")
    public ResponseResult add(@RequestBody NursingPlanDto nursingPlanDto) {
        log.info("新增计划：{}", nursingPlanDto);
        nursingPlanService.addPlan(nursingPlanDto);
        return success();
    }

    //根据ID查询
    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID查询")
    public ResponseResult<NursingPlanVo> getById(@ApiParam(value = "计划ID",required = true)
                                                     @PathVariable Long id) {
        log.info("查询ID：{}", id);
        NursingPlanVo nursingPlanVo = nursingPlanService.getPpById(id);
        return success(nursingPlanVo);
    }

    //编辑计划
    @PutMapping("/{id}")
    @ApiOperation(value = "编辑计划信息")
    public ResponseResult updatePlanMes(@RequestBody NursingPlanDto nursingPlanDto,@PathVariable Long id ) {
        log.info("编辑计划{}", nursingPlanDto);
        nursingPlanService.updatePlan(nursingPlanDto);
        return success();
    }

    //删除计划
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除计划")
    public ResponseResult remove(@ApiParam(value = "计划ID",required = true)
                                     @PathVariable Long id) {
        log.info("删除计划：{}",id);
        nursingPlanService.removePlan(id);
        return success();
    }

    //启用、禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用、禁用计划")
    public ResponseResult updateStatus(@ApiParam(value = "计划ID",required = true)
                                           @PathVariable Long id,
                                       @ApiParam(value = "计划状态",required = true)
                                       @PathVariable Integer status) {
        log.info("计划：{}，状态：{}",id,status);
        nursingPlanService.updatePlanStatus(id,status);
        return success();
    }


}
